<template>
    <div>
        <el-card>
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入查询内容">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <el-table
            :data="ordersList"
            style="width=100%"
            border
            stripe>
                <el-table-column label="#" type="index"></el-table-column>
                <el-table-column label="订单编号" prop="order_number"></el-table-column>
                <el-table-column label="订单价格" prop="order_price"></el-table-column>
                <el-table-column label="是否付款" prop="pay_status">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.pay_status != 0">已付款</el-tag>
                        <el-tag type="danger" v-else>未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="是否发货" prop="is_send">
                    <template slot-scope="scope">
                        {{scope.row.is_send}}
                    </template>
                </el-table-column>
                <el-table-column label="下单时间" prop="create_time">
                    <template slot-scope="scope">
                        <!-- {{scope.row.creat_time | dataFormat}} -->
                        {{scope.row.create_time | dataFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleClickEdit(scope.row)"></el-button>
                        <el-button type="success" icon="el-icon-location" size="mini" @click="handleClickLocation(scope.row)"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-size="queryInfo.pagesize"
            :page-sizes="page_sizes"
            :total="total"
            layout="total,sizes,prev,pager,next,jumper"></el-pagination>
        </el-card>

        <el-dialog
        title="编辑地址"
        :visible.sync="editDialogVisible"
        width="60%"
        @close="editDialogClosed">
            <el-form label-width="6rem" ref="editRef" :rules="editRules" :model="editForm">
                <el-form-item label="省市区/县" prop="address"> 
                    <el-cascader
                    :props="cascaderProps"
                    v-model="editForm.address"
                    :options="cityData"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="location">
                    <el-input v-model="editForm.location"></el-input>
                </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogVisible = false">取消</el-button>
                <el-button type="primary" @click="editDialogVisible = false">确认</el-button>
            </span>
        </el-dialog>

        <el-dialog
        title="详细地址"
        :visible.sync="locationDialogVisible"
        width="80%"
        @close="locationDialogClosed">
            <el-timeline :reverse="false">
                <el-timeline-item
                v-for="(activity, index) in locationInfo"
                :key="index"
                :timestamp="activity.time">
                {{activity.context}}
                </el-timeline-item>
            </el-timeline>
        </el-dialog>
    </div>
</template>

<script>
    import cityData from './city.data-3'
    import kuaidiData from './kuaidiData'

    export default {
        data() {
            return {
                ordersList              : [],
                // 查询条件
                queryInfo               : {
                    query               : '',
                    pagenum             : 1,
                    pagesize            : 10
                },
                total                   : 0,
                page_sizes              : [5, 10, 20, 50],

                editDialogVisible       : false,
                locationDialogVisible   : false,

                editForm                : {
                    address             : [],
                    location            : ''
                },
                editRules               : {
                    address             : [{ required: true, message: '请选择一个地区', trigger: 'blur' }],
                    location            : [{ required: true, message: '请填写详细地址', trigger: 'blur' }]
                },

                cascaderProps           : {
                    expandTrigger       : 'hover'
                    // value               : 'value',
                    // label               : 'label',
                    // children            : 'children'
                },

                cityData,
                // kuaidiData,

                locationInfo            : kuaidiData
            }
        },

        created() {
            this.getOrderList()
            const testDate = new Date()
            console.log('0.' + +testDate)
            console.log(Math.random())
        },

        methods: {
            async getOrderList() {
                const { data: res } = await this.$http.get('/orders',  { params: this.queryInfo })
                if (res.meta.status == 200) {
                    this.ordersList = res.data.goods
                    this.total = res.data.total
                } else {
                    this.$message.error('获取订单数据列表失败')
                }
            },
            handleCurrentChange(newPage) {
                this.queryInfo.pagenum = newPage
                this.getOrderList()
            },
            handleClickEdit(row) {
                this.editDialogVisible = true
            },
            async handleClickLocation() {
                // const { data: res } = await this.$http.get('/kuaidi/4312338288332')
                // if (res.meta.status == 200) {
                //     this.locationInfo = res.data
                //     this.locationDialogVisible = true   
                // } else {
                //     this.$message.error('获取快递信息失败')
                // }
                // this.locationInfo = this.kuaidiData
                this.locationDialogVisible = true
            },

            // 关闭dialog执行函数
            editDialogClosed() {
                this.$refs.editRef.resetFields()
                },
            locationDialogClosed() {

            }
        }
    }
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';

    .el-table{
        margin-top: 1rem;
        margin-bottom: 1rem;
    }
    .el-form{
        padding: 0 1rem;
        .el-cascader{
            width: 100%;
        }
    }
</style>